package com.quarkus.api;

import java.time.Duration;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;

public class CreateApi {
    
    public static void test_01(){

        Uni.createFrom().item(1).subscribe().with(System.out::println);

    }

    public static void test_02(){

        Multi.createFrom().items(1,2,3,4,5).subscribe(new Subscriber<Integer>(){

            Subscription sub;

            @Override
            public void onComplete() {
                System.out.println("onComplete");
            }

            @Override
            public void onError(Throwable arg0) {
                System.out.println(arg0);
            }

            @Override
            public void onNext(Integer arg0) {
                System.out.println("onNext");
                System.out.println(arg0);
                sub.request(1);
            }

            @Override
            public void onSubscribe(Subscription arg0) {
                sub = arg0;
                sub.request(1);
                System.out.println("onSubscribe");
            }
            
        });

    }

    public static void test_03(){

        Multi.createFrom().range(1, 10)
                .subscribe()
                .asIterable()
                .forEach(System.out::println);

    }

    public static void test_04(){

        Multi.createFrom().ticks().every(Duration.ofMillis(1000))
                        .subscribe()
                        .asIterable()
                        .forEach(System.out::println);

    }

    public static void test_05(){

        Multi.createFrom().ticks().every(Duration.ofMillis(1000))
        .map(num->{
            System.out.println(num);
            return num;
        })
        .subscribe();

    }

    public static void main(String[] args) {
        test_05();
    }

}
